<?php

class View {
	
	protected $viewPath;
	
	function __construct($viewName, $vars = null) {
		$this->viewPath = "lib/views/$viewName.php";
		if( is_array($vars) ) {
			// replace BufferedViews with their contained buffers
			foreach( $vars as $key=>$var ) if( $var instanceof BufferedView ) $vars[$key] = $var->getBuffer();
			// put the variables in the local symbol table for use by the view itself
			extract( $vars );
		}
		if( file_exists($this->viewPath) ) include( $this->viewPath );
		else throw new Exception('Could not find view');
	}
	
	static function show( $var ) {
		if( isset( $var ) ) echo $var;
	}

	
}